<template>
	<template v-for="(item, index) in filters" :key="item">
		<a-tag closable @close="tagClose(index)">{{ item.Name }} {{ item.Type }} '{{ item.Value }}'</a-tag>
	</template>
</template>

<script>
export default {
	name: 'tableSearch',
	props: [],
	data() {
		return {
			title: '搜索工具栏',
			filters: [],
		};
	},
	mounted() {
		this.init();
		this.hashListener();
	},
	methods: {
		/**
		 * @function 初始化
		 */
		init() {
			var hash = location.hash.substring(1);
			if (hash.length > 1) {
				this.filters = JSON.parse(decodeURI(hash));
			}
		},
		/**
		 * @function 监听URL的hash #后面的参数变化
		 */
		hashListener() {
			var that = this;
			window.addEventListener(
				'hashchange',
				() => {
					that.init();
				},
				false
			);
		},
		/**
		 * @function 关闭搜索标签tag
		 * @param {*} index 下标
		 */
		tagClose(index) {
			this.filters.splice(index, 1);
			if (this.filters.length <= 0) {
				location.hash = '#';
				this.$parent.GetData();
			} else {
				location.hash = '#' + JSON.stringify(this.filters);
			}
			//this.$parent.GetData();
		},
	},
};
</script>

<style></style>
